package main

import (
	"fmt"
	"time"
)

/**
*  User: zhanbei
*  Date: 2025/10/27
*  Description: CS:GO动画 - 反恐精英CT与T对峙场景
 */

// CT (反恐精英) ASCII艺术 - 带M4A1
var ctWithGun = []string{
	"         ___________",
	"        |  CT  ◢◣  |      ",
	"        |_____◥◤__|      ",
	"          ║ ◉ ◉ ║        ",
	"          ║  >  ║         ",
	"══════════╬═════╬══       M4A1",
	"         ╔╝     ╚╗        ",
	"        ╔╝███████╚╗       ",
	"       ╔╝ [ARMOR] ╚╗      ",
	"      ╔╝  ███████  ╚╗     ",
	"     ╔╩════════════╩╗     ",
	"     ║  ║        ║  ║     ",
	"     ║  ║        ║  ║     ",
	"    ╔╝  ║        ║  ╚╗    ",
	"   ╔╝   ║        ║   ╚╗   ",
	"   ║   ╔╝        ╚╗   ║   ",
	"  ╔╩══╗║          ║╔══╩╗  ",
	"  ║___║║          ║║___║  ",
}

// T (恐怖分子) ASCII艺术 - 带AK47
var tWithGun = []string{
	"       _____________",
	"      |  ▓▓▓▓▓▓  |         ",
	"      |___[T]___|          ",
	"        ║ ◉ ◉ ║            ",
	"        ║  Λ  ║            ",
	"        ║ === ║            ",
	"AK47    ╬═════╬═══════════",
	"       ╔╝     ╚╗           ",
	"      ╔╝  ███  ╚╗          ",
	"     ╔╝ [VEST] ╚╗         ",
	"    ╔╝  ███████  ╚╗        ",
	"    ║╔════════════╗║       ",
	"    ║║  ║      ║  ║║       ",
	"    ║║  ║      ║  ║║       ",
	"   ╔╝╚╗ ║      ║ ╔╝╚╗      ",
	"  ╔╝  ║ ║      ║ ║  ╚╗     ",
	"  ║  ╔╝ ║      ║ ╚╗  ║     ",
	" ╔╩═╗║ ╔╝      ╚╗ ║╔═╩╗    ",
	" ║__║║ ║        ║ ║║__║    ",
}

// RunCSGO CS:GO角色对峙动画
func RunCSGO() {
	width, height := getTerminalSize()

	// 隐藏光标
	hideCursor()
	defer showCursor()

	// 清屏
	clearScreen()

	centerY := height / 2

	// 显示标题
	moveCursor(width/2-20, 2)
	setColor(91) // 红色
	fmt.Print("╔════════════════════════════════════╗")
	moveCursor(width/2-20, 3)
	fmt.Print("║  COUNTER-STRIKE: GLOBAL OFFENSIVE  ║")
	moveCursor(width/2-20, 4)
	fmt.Print("╚════════════════════════════════════╝")
	resetColor()

	time.Sleep(1 * time.Second)

	// 第一幕：CT从左边出现
	moveCursor(width/2-15, centerY-12)
	setColor(96) // 青色 (CT的颜色)
	fmt.Print(">>> Counter-Terrorists <<<")
	resetColor()
	time.Sleep(500 * time.Millisecond)

	// CT从左边走到中间
	ctStartX := 5
	ctEndX := width/2 - 35

	for x := ctStartX; x <= ctEndX; x += 2 {
		// 清除区域
		for i := 0; i < 20; i++ {
			moveCursor(1, centerY-10+i)
			for j := 0; j < width/2; j++ {
				fmt.Print(" ")
			}
		}

		// 绘制CT
		for i, line := range ctWithGun {
			moveCursor(x, centerY-9+i)
			setColor(36) // 青色
			fmt.Print(line)
		}
		resetColor()

		time.Sleep(70 * time.Millisecond)
	}

	time.Sleep(500 * time.Millisecond)

	// 第二幕：T从右边出现
	moveCursor(width/2+5, centerY-12)
	setColor(93) // 黄色 (T的颜色)
	fmt.Print(">>> Terrorists <<<")
	resetColor()
	time.Sleep(500 * time.Millisecond)

	// T从右边走到中间
	tStartX := width - 25
	tEndX := width/2 + 5

	for x := tStartX; x >= tEndX; x -= 2 {
		// 清除右半区域
		for i := 0; i < 22; i++ {
			moveCursor(width/2, centerY-10+i)
			for j := 0; j < width/2; j++ {
				fmt.Print(" ")
			}
		}

		// 绘制T
		for i, line := range tWithGun {
			moveCursor(x, centerY-9+i)
			setColor(33) // 黄色
			fmt.Print(line)
		}
		resetColor()

		time.Sleep(70 * time.Millisecond)
	}

	time.Sleep(1 * time.Second)

	// 第三幕：对峙
	clearScreen()

	// 重新绘制标题
	moveCursor(width/2-10, 2)
	setColor(91)
	fmt.Print("⚠  STANDOFF!  ⚠")
	resetColor()

	// 绘制CT
	for i, line := range ctWithGun {
		moveCursor(ctEndX, centerY-9+i)
		setColor(36)
		fmt.Print(line)
	}

	// 绘制T
	for i, line := range tWithGun {
		moveCursor(tEndX, centerY-9+i)
		setColor(33)
		fmt.Print(line)
	}
	resetColor()

	// VS标志
	moveCursor(width/2-1, centerY)
	setColor(91)
	fmt.Print("╔═══╗")
	moveCursor(width/2-1, centerY+1)
	fmt.Print("║VS ║")
	moveCursor(width/2-1, centerY+2)
	fmt.Print("╚═══╝")
	resetColor()

	time.Sleep(1 * time.Second)

	// 第四幕：开火效果
	for i := 0; i < 6; i++ {
		// 枪口火光（更强烈的效果）
		moveCursor(ctEndX+1, centerY-3)
		setColor(93)
		fmt.Print("🔥💥")
		moveCursor(tEndX+1, centerY-3)
		fmt.Print("🔥💥")

		// 子弹轨迹
		moveCursor(ctEndX+20, centerY-3)
		setColor(91)
		fmt.Print("━━━━━►")
		moveCursor(tEndX-10, centerY-3)
		fmt.Print("◄━━━━━")
		resetColor()

		time.Sleep(120 * time.Millisecond)

		// 清除火光
		moveCursor(ctEndX+1, centerY-3)
		fmt.Print("      ")
		moveCursor(tEndX+1, centerY-3)
		fmt.Print("      ")
		moveCursor(ctEndX+20, centerY-3)
		fmt.Print("        ")
		moveCursor(tEndX-10, centerY-3)
		fmt.Print("        ")

		time.Sleep(80 * time.Millisecond)
	}

	time.Sleep(500 * time.Millisecond)

	// 第五幕：两边走出屏幕
	steps := 40
	for step := 0; step < steps; step++ {
		// 清屏
		for i := 0; i < 22; i++ {
			moveCursor(1, centerY-10+i)
			for j := 0; j < width; j++ {
				fmt.Print(" ")
			}
		}

		// CT向左走
		ctX := ctEndX - step*2
		if ctX >= -30 {
			for i, line := range ctWithGun {
				moveCursor(ctX, centerY-9+i)
				setColor(36)
				fmt.Print(line)
			}
		}

		// T向右走
		tX := tEndX + step*2
		if tX <= width {
			for i, line := range tWithGun {
				moveCursor(tX, centerY-9+i)
				setColor(33)
				fmt.Print(line)
			}
		}
		resetColor()

		time.Sleep(50 * time.Millisecond)
	}

	// 结束信息
	clearScreen()
	moveCursor(width/2-15, height/2-1)
	setColor(92)
	fmt.Println("╔══════════════════════════╗")
	moveCursor(width/2-15, height/2)
	fmt.Println("║  MATCH IN PROGRESS...   ║")
	moveCursor(width/2-15, height/2+1)
	fmt.Println("╚══════════════════════════╝")
	resetColor()

	moveCursor(width/2-10, height/2+3)
	setColor(37)
	fmt.Print("Good luck, have fun!")
	resetColor()

	moveCursor(1, height)
	time.Sleep(2 * time.Second)
}
